﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP.Electric.Common;

namespace HYRElectric.WirePlace
{
	public partial class DlgCableChannel : System.Windows.Forms.Form
	{
		public DlgCableChannel()
		{
			this.InitializeComponent();
		}

		private void DlgCableChannel_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.xmlHelper.LoadXml(this.path, "Root");
			this.LoadDlgData();
			if (string.IsNullOrEmpty(this.txtChannelWidth.Text))
			{
				this.txtChannelWidth.Text = "800";
			}
			if (string.IsNullOrEmpty(this.txtChannelDeep.Text))
			{
				this.txtChannelDeep.Text = "600";
			}
		}

		private void DlgCableChannel_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SaveDlgData();
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYCableChannel"));
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYCableChannel", "Params"));
			this.xmlHelper.SetAttribute("Width", this.txtChannelWidth.Text.Trim());
			this.xmlHelper.SetAttribute("Deep", this.txtChannelDeep.Text.Trim());
			this.xmlHelper.SaveXml("");
		}

		private void LoadDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYCableChannel", "Params"));
			this.txtChannelWidth.Text = this.xmlHelper.GetAttribute("Width");
			this.txtChannelDeep.Text = this.xmlHelper.GetAttribute("Deep");
		}

		private void txtChannelDeep_KeyPress(object sender, KeyPressEventArgs e)
		{
			Common.IsPlusDouble(e, this.txtChannelDeep.Text);
		}

		private void txtChannelWidth_KeyPress(object sender, KeyPressEventArgs e)
		{
			Common.IsDouble(e, this.txtChannelWidth);
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (Common.CheckValue(this.txtChannelWidth, "电缆沟沟宽") && Common.CheckValue(this.txtChannelDeep, "电缆沟沟深"))
			{
				base.DialogResult = DialogResult.OK;
			}
		}

		private YArchitech.MEP.Electric.Common.XmlHelper xmlHelper = new YArchitech.MEP.Electric.Common.XmlHelper();

		private string path = Path.Combine(new string[]
		{
			Product.WorkingLocation + "CableChannel.xml"
		});

		private const string Root = "Root";

		private const string Node = "HYCableChannel";

		private const string ChildNode = "Params";

		private const string ChannelWidth = "Width";

		private const string ChannelDeep = "Deep";
	}
}
